﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RoutingTable
{
    class MSG
    {
        // Message Information    *****************************************************************
        public  const   float   CET		= 16.56f;   // The Consumption of Engergy Transmission
        public  const   float   CER		= 12.5f;    // The Consumption of Engergy Receiption
		public	const	float	MAC		= 15f;		// MAC Generation consume
		public  const   int		SEED        = 1;
		public	const	int		PRM_TE	= 1000;
		public	const	int		THC		= 2;
		public	const	int		MR		= 4;		// Mac per a Report

		public	int		AKC = 0;

		Random randomObject = new Random( SEED );

        // Sum The Consumption of Engergy Transmission  *******************************************
        public float ConsumeForTransmission( float e )
        {
            return e + CET;
        } // public float ConsumeForTransmission( float e )


        // Sum The Consumption of Engergy Receiption    *******************************************
        public float ConsumeForReceiption( float e )
        {
            return e + CER;
        } // public float ConsumeForReceiption( float e )

		public float ConsumeMACGerneration( float e )
		{
			//return 0;
			return e + MAC;
		}

		public float CalculatePDM( int trc, int rrc, int shc )
		{
			return ( ( trc / rrc ) * 100 ) + shc;
		}

		public int ChkOverlapMac( int[] mac, int tmp )
		{
			for ( int i = 0; i < MR; i++ )
			{
				if ( mac[i] == tmp )
					return -1;
			}

			return tmp;
		}

		public int GenerateKey( int[] keys )
		{
			int tmp;
			tmp = randomObject.Next( 0, NODE.KCNT );

			return keys[tmp];

			//int tmp;

			//Random r = new Random( ( int )DateTime.Now.Ticks );
			//System.Threading.Thread.Sleep( 1 );

			//tmp = r.Next( 0, NODE.KCNT - 1 );
			//return keys[tmp];
		}

		public int ForgedReport( int tmp )
		{
			tmp = tmp - ( tmp * 2);
			return tmp;
		}

		public bool ChkForgedMAC( int[] array, int value )
		{
			for ( int i = 0; i < MR; i++ )
			{
				if ( array[i] == -1 )
					continue;

				if ( array[i] < 0 )
					return true;
				//int tmp = ( array[i] * 2 ) + array[i];

				//if ( tmp == value )
				//    return true;
			}
			return false;
		}

		public bool ChkForgedKey( int[] array, int[] key )
		{
			for ( int i = 0; i < MR; i++ )
			{
				for ( int j = 0; j < NODE.KCNT; j++ )
				{
					int tmp = ( array[i] * 2 ) + array[i];

					if ( tmp == key[j] )
						return true;
				}
			}
			return false;
		}

		public int MakeRandom( int max )
		{
			int tmp;
			//Random r = new Random( ( int )DateTime.Now.Ticks );
			//System.Threading.Thread.Sleep( 1 );

			//tmp = r.Next( 1, max );
			tmp = randomObject.Next( 0, 99 );
			return tmp;
		}

    }
}
